package com.wmh.baseservice.operationaid.controller.picture;

import com.wmh.baseservice.common.utils.page.pojo.PageResult;
import com.wmh.baseservice.common.utils.page.util.PageUtil;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.operationaid.entity.ProductPicture;
import com.wmh.baseservice.operationaid.pojo.vo.productPicture.ProductPicturePageReqVO;
import com.wmh.baseservice.operationaid.service.ProductPictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static com.wmh.baseservice.common.utils.returnbody.ReturnBody.success;

@Validated
@RestController
@RequestMapping("operationAid/productPicture")
@Api(tags = "商品数据-商品图片")
@Slf4j
public class ProductPictureController {

    @Resource
    private ProductPictureService productPictureService;

    @ApiOperation(value = "获取商品图片类别")
    @GetMapping("/category")
    public String getCategory() {
        List<String> categoryList = productPictureService.getCategory();
        return success(categoryList);
    }

    @ApiOperation(value = "分页接口")
    @GetMapping("/page")
    public String page(@Valid ProductPicturePageReqVO reqVO) {
        PageResult<ProductPicture> pageResult = new PageUtil<ProductPicture>(reqVO).startPage((page, wrapper) -> {
            wrapper.lambda().eq(ProductPicture::getCategory, reqVO.getCategory());
            productPictureService.page(page, wrapper);
        });
        return ReturnBody.success(pageResult);
    }
}
